import request from '@/utils/request';

const baseURL = '/fileManagement';
const post = (url, data, headers) =>
  new Promise((resolve, reject) => {
    request({
      url: `${baseURL}${url}`,
      method: 'POST',
      data,
      headers
    })
      .then(res => resolve(res.data))
      .catch(err => reject(err.data));
  });

export const get = (url, params, headers) =>
  new Promise((resolve, reject) => {
    request({
      url: `${baseURL}${url}`,
      method: 'GET',
      params,
      headers
    })
      .then(res => resolve(res.data))
      .catch(err => reject(err.data));
  });
/**
 * 分页查询文件集合
 * @description 描述信息
 * @remarks 备注
 * @async
 * @param {String}  []
 * @returns {Object}
 */
export const querylist = params => post('/selectPageList', params);

/**
 * 保存或更新文件预览信息
 * @description 描述信息
 * @remarks 备注
 * @async
 * @param {String}  []
 * @returns {Object}
 */
export const saveOrUpdate = params => post('/saveOrUpdate', params);

/**
 * 保存或更新文件预览信息
 * @description 描述信息
 * @remarks 备注
 * @async
 * @param {String}  []
 * @returns {Object}
 */
export const upload = file =>
  post(
    '/minio/upload',
    { file },
    {
      'Content-Type': 'multipart/form-data'
    }
  );

/**
 * 附件删除
 * @description 描述信息
 * @remarks 备注
 * @async
 * @param {String}  []
 * @returns {Object}
 */
export const deleteFileById = fileName => get('/minio/remove', { fileName });
